home *** CD-ROM | disk | FTP | other *** search
/ ftp.qualcomm.com / 2014.06.ftp.qualcomm.com.tar / ftp.qualcomm.com / eudora / developers / emsapi / carbon_emsapi.sit.hqx / Macintosh API Support / ctencode.h < prev    next >
Text File  |  2001-03-08  |  3KB  |  98 lines

  1. /* ======================================================================
  2.  
  3.     Function to encode and decode binary data to quoted-printable data.
  4.     Code extracted from Eudora. Based on Steve Dorner's code.
  5.  
  6.     Filename:            ctencode.h
  7.     Last Edited:        March 7, 1997
  8.     Authors:            Laurence Lundblade, Myra Callen
  9.     Copyright:            1995, 1996 QUALCOMM Inc.
  10.     Technical support:    <emsapi-info@qualcomm.com>
  11. */
  12.  
  13. #ifndef CTENCODE_H
  14. #define CTENCODE_H
  15.  
  16. // Return values for encoders and decoders
  17. #define kCTEDoneOK    0
  18. #define kCTEFailed    1
  19.  
  20. typedef unsigned char *UPtr, *PStr;
  21.  
  22. /* ----------------- Quoted-Printable ------------------- */
  23.  
  24. // state buffer for QP encoding. Initialize all values to zero.
  25. typedef enum {
  26.     qpNormal,
  27.     qpEqual,
  28.     qpByte1
  29. } QPStates;
  30.  
  31. // state buffer for encoding
  32. typedef struct {
  33.     long    nCurLineLen; /* Number of characters outputed to current line */
  34.     char    cLastChar;     /* Last character read in */
  35. } EncQP, *EncQPPtr;
  36.  
  37. // state buffer for decoding
  38. typedef struct {
  39.     QPStates    state;
  40.     Byte         lastChar;
  41.     long        spaceCount;
  42. } DecQP, *DecQPPtr, **DecQPHandle;
  43.  
  44. // to do the quoted-printable encoding/decoding
  45. long    EncodeQP(const UPtr binPtr, long binLen,
  46.                  const UPtr qpPtr, long *qpBufSize, long *eQP);
  47. long    DecodeQP(const UPtr qpPtr, long qpLen,
  48.                  const UPtr binPtr, long *binLen,
  49.                  const DecQPPtr dQP, long *decErrCnt);
  50.  
  51. /* ----------------- Base 64 ------------------- */
  52.  
  53. // state buffer for encoding
  54. typedef struct {
  55.     Byte    partial[4];
  56.     short    partialCount;
  57.     short    bytesOnLine;
  58. } Enc64, *Enc64Ptr, **Enc64Handle;
  59.  
  60. // state buffer for decoding
  61. typedef struct {
  62.     short    decoderState;    /* which of 4 bytes are we seeing now? */
  63.     long    invalCount;        /* how many bad chars found so far? */
  64.     long    padCount;        /* how many pad chars found so far? */
  65.     Byte    partial;        /* partially decoded byte from/for last/next time */
  66.     Boolean    wasCR;            /* was the last character a carriage return? */
  67. } Dec64, *Dec64Ptr, **Dec64Handle;
  68.  
  69. // to do the base 64 encoding/decoding
  70. short Encode64(const UPtr bin, long len,
  71.                const UPtr sixFour, long *sixFourLen, Enc64Ptr e64);
  72. short Decode64(const UPtr sixFour, long sixFourLen,
  73.                const UPtr bin, long *binLen,
  74.                const Dec64Ptr d64, long *decErrCnt);
  75.  
  76. /* ----------------- Identify the CTE ------------------- */
  77. #define kCTEncodeHdrCStr    "Content-Transfer-Encoding:"
  78. #define kCTEncodeHdrLen        26
  79.  
  80. // Valid return values for RFC822_ParseCTE which specify the transfer
  81. // encoding found in the parsed header line
  82. typedef enum {
  83.     CTE_Error,
  84.     CTE_Base64,
  85.     CTE_QP,
  86.     CTE_7bit,
  87.     CTE_8bit,
  88.     CTE_Binary,
  89.     CTE_NONE,
  90.     CTE_ASK
  91. } TrEncType;
  92.  
  93. TrEncType    RFC822_ParseCTE(const char *src);
  94. Handle        RFC822_MakeCTE(TrEncType mechanism);
  95. char        *RFC822_ExtractCTE(const char *pFullHeader);
  96.  
  97. #endif /* ENCODING_H */
  98.